package com.kit.data.kitopeso.adapter;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.kit.data.kitopeso.R;
import com.kit.data.kitopeso.base.BaseBindingAdapter1;
import com.kit.data.kitopeso.databinding.KitoFbSubmitItem2Binding;
import com.kit.data.kitopeso.tools.ResUtils;
import com.kit.data.kitopeso.tools.ViewUtils;


import java.util.List;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

public class FbImageAdapter extends BaseBindingAdapter1<String, KitoFbSubmitItem2Binding> {


    public FbImageAdapter(List<String> dataList) {
        super(dataList);
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void bindData(KitoFbSubmitItem2Binding binding, String item, int position) {
        if (TextUtils.isEmpty(item)) {
            binding.tvDelete.setVisibility(View.GONE);
            binding.tvIcon.setImageResource(R.mipmap.fb_sumit_add);
            binding.tvIcon.setTag(position);
            binding.tvIcon.setOnClickListener(v -> {
                ViewUtils.viewScale(v);
                if (onBtnItemClickListener != null) {
                    onBtnItemClickListener.onItemClick((Integer) binding.tvIcon.getTag());
                }
            });
        } else {
            binding.tvDelete.setVisibility(View.VISIBLE);
            int radius = ResUtils.d(R.dimen.dp_8);
            Glide.with(binding.tvIcon)
                    .load(item)
                    .placeholder(R.color.placeholder_icon)
                    .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(radius, 0, RoundedCornersTransformation.CornerType.ALL)))
                    .into(binding.tvIcon);
            binding.tvDelete.setTag(position);
            binding.tvDelete.setOnClickListener(v -> {
                ViewUtils.viewScale(v);
                if (onBtnItemClickListener != null) {
                    onBtnItemClickListener.onItemClick((Integer) binding.tvDelete.getTag());
                }
            });
        }
    }

    @Override
    protected int getItemType(String item) {
        return 0;
    }

    @Override
    protected KitoFbSubmitItem2Binding createBinding(LayoutInflater inflater, ViewGroup parent, int viewType) {
        return KitoFbSubmitItem2Binding.inflate(inflater, parent, false);
    }

}
